package com.foreveross.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foreveross.common.Constants;
import com.foreveross.dao.LogDAO;
import com.foreveross.dao.SysUserDAO;
import com.foreveross.dao.TenementDAO;
import com.foreveross.vo.HrBusiness;
import com.foreveross.vo.HrHouses;
import com.foreveross.vo.SysUser;
import com.foreveross.vo.Tenement;
import com.foreveross.vo.TenementHouse;

@Service("tenementService")
@Transactional
public class TenementService extends BaseService {

	@Resource
	public TenementDAO tenementDAO;

	public List<Tenement> findTenementList(String house_id, String name, String phone,
			int pageIndex, int pageSize, String userId) throws Exception {
		List<Tenement> listTenement = tenementDAO.findTenementList(house_id, name, phone, pageIndex, pageSize,userId);
		for (Tenement tenement : listTenement){
			tenement.setHouse_id(tenement.getHouseId().getId());
			tenement.setHouse_name(tenement.getHouseId().getName());
		}
		return listTenement;
	}

	public long getUserListCount(String house_id, String name, String phone, String userId) throws Exception {
		return tenementDAO.getTenementListCount(house_id, name, phone,userId);
	}

	@Transactional
	public void deleteTenementList(String tenementIds) throws Exception {
		for (String tenementId : tenementIds.split(",")) {
			tenementDAO.deleteTenement(tenementId);
		}
	}

	public List<Tenement> getTenementSelect(String userId, String id, 
			int pageIndex, int pageSize) throws Exception{
		List<Tenement> tenementList = tenementDAO.findTenementList(null, null, null, pageIndex, pageSize, userId);
		if (id != null && !"".equals(id)) {
			for (Tenement tenement : tenementList) {
				if (tenement.getId().equals(id))
					tenement.setSelected(true);
			}
		}
		return tenementList;
	}

}
